package one.bugu.android.demon.ui.adapter.snatch;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import one.bugu.android.demon.R;
import one.bugu.android.demon.bean.ChooseDataBean;

/**
 * 选择窗口数字
 */
public class ChooseSnatchAdapter extends BaseAdapter {
    private List<ChooseDataBean> mList;
    private Activity mContext;

    public ChooseSnatchAdapter(Activity context, List<ChooseDataBean> list) {
        super();
        this.mContext = context;
        if (list == null) {
            mList = new ArrayList<>();
        } else {
            this.mList = list;
        }
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public ChooseDataBean getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("SetTextI18n")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_choose_snatch_item, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mTvChooseItem.setText(mList.get(position).getNumber());
        if(!mList.get(position).isCanClick()){
            holder.mLlChooseItem.setBackgroundResource(R.drawable.shape_choose_not_click);
        }else{
            holder.mLlChooseItem.setBackgroundResource(R.drawable.shape_choose_can_click);
        }
        holder.mLlChooseItem.setClickable(!mList.get(position).isCanClick());
        return convertView;
    }

    public static class ViewHolder {
        public View rootView;
        public TextView mTvChooseItem;
        public LinearLayout mLlChooseItem;

        public ViewHolder(View rootView) {
            this.rootView = rootView;
            this.mTvChooseItem = rootView.findViewById(R.id.tv_choose_item);
            this.mLlChooseItem = rootView.findViewById(R.id.ll_choose_item);
        }
    }
}
